<script setup>
import { useRouter, useRoute } from 'vue-router'
import { ref, onMounted, nextTick } from 'vue'
import Axios from 'axios'
Axios.interceptors.request.use(function (config) {
  // 在发送请求之前做些什么
  return config;
}, function (error) {
  // 对请求错误做些什么
  return Promise.reject(error);
});

// 添加响应拦截器
Axios.interceptors.response.use(function (response) {
  // 2xx 范围内的状态码都会触发该函数。
  // 对响应数据做点什么
  console.log('response', response)
  return response;
}, function (error) {
  // 超出 2xx 范围的状态码都会触发该函数。
  // 对响应错误做点什么
  return Promise.reject(error);
});
const router = useRouter()
const route = useRoute()

onMounted(() => {
  nextTick(() => {
    // ????? 29号解开
    setinit()
    // if (route.query.merchID && route.query.subchannel) {
    //   console.log('传了参数')
    //   location.href = (`https://wjmt.nextjoy.com.cn?merchID=${route.query.merchID}&subchannel=${route.query.subchannel}`)
    // } else {
    //   console.log('没有参数')
    //   location.href = (`https://wjmt.nextjoy.com.cn`)
    // }
  })
})
// http://192.168.180.48:5173/#/mtydpage?merchID=12&subchannel=5680
function setinit() {
  // debugger
  let userAgent = navigator.userAgent.toLowerCase();
  // 用 test 匹配浏览器信息
  if (/ipad|iphone|midp|rv:1.2.3.4|ucweb|android|windows ce|windows mobile/.test(userAgent)) {
    isydsb()
  } else {
    if (route.query.merchID && route.query.subchannel) {
      console.log('传了参数')
     
      location.href = (`https://wjmt.nextjoy.com.cn/?merchID=${route.query.merchID}&subchannel=${route.query.subchannel}`)
      // location.href = (`https://wjmt.nextjoy.com.cn?merchID=${route.query.merchID}&subchannel=${route.query.subchannel}`)
    } else {
      console.log('没有参数')
      location.href = (`https://wjmt.nextjoy.com.cn`)
      // location.href = (`https://wjmt.nextjoy.com.cn`)
    }
  }
}
// 判断设备
function isydsb() {
  const ua = window.navigator.userAgent
  if (ua.indexOf('Android') >= 0) {
    //  andrioid
    // router.push({
    //   name: 'mtydpage',
    //   query: { 
    //     Downloadpath: Downloadpath.value
    //   },
    // })
    let ua = navigator.userAgent.toLowerCase();//获取判断用的对象
    if (ua.match(/MicroMessenger/i) == "micromessenger") {
      // let urlpath = `https://mtapk.game.nextjoy.com/game/android/wjmt_1.4.4.0_${route.query.merchID}_${route.query.subchannel}.apk`
      // down(urlpath)
    } else {
      if (route.query.merchID && route.query.subchannel) {
        console.log(route.query.merchID, route.query.subchannel)
        let urlpath = `https://mtapk.game.nextjoy.com/game/android/1.5.0.0/WJMT_NextJoy_GW_1.5.0.0.apk`
        down(urlpath)
      } else {
        let urlpath = `https://mtapk.game.nextjoy.com/game/android/1.5.0.0/WJMT_NextJoy_GW_1.5.0.0.apk`
        down(urlpath)
      }
    }
  } else {
    // ios
    location.href = "https://apps.apple.com/cn/app/id1639842761"
    window.open('https://apps.apple.com/cn/app/id1639842761')
  }
}
function down(path) {
  let objectUrl = path
  const a = document.createElement("a")
  a.href = objectUrl
  a.click()
  window.URL.revokeObjectURL(objectUrl);
  a.remove('')
}
</script>

<template>
  <!-- <button @click="ttttt()">t123</button> -->
  <img class="h-[100vh] w-[100vw]" src="../assets/img/mtydpage.jpg" alt="">
</template>